package com.hb.game.pk.ui.activity.mine.setting;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.hb.game.pk.APP;
import com.hb.game.pk.AppManager;
import com.hb.game.pk.R;
import com.hb.game.pk.base.BaseActivity;
import com.hb.game.pk.ui.activity.login.LoginActivity;
import com.hb.game.pk.ui.activity.mine.setting.account.AccountActivity;
import com.hb.game.pk.utils.AppUtils;
import com.hb.game.pk.utils.SpUtils;
import com.hb.game.pk.widgets.MineItemView;
import com.hb.game.pk.widgets.titlebar.TitleBar;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class SettingActivity extends BaseActivity {
    @BindView(R.id.title_bar)
    TitleBar titleBar;
    @BindView(R.id.miv_account)
    MineItemView mivAccount;
    @BindView(R.id.miv_version)
    MineItemView mivVersion;
    @BindView(R.id.btn_login_out)
    Button btnLoginOut;
    @BindView(R.id.iv_sound)
    ImageView ivSound;
    @BindView(R.id.rl_sound)
    RelativeLayout rlSound;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_setting;
    }

    @Override
    protected int getRootViewId() {
        return R.id.layout_root;
    }

    @Override
    protected int getRefreshId() {
        return 0;
    }

    @Override
    protected int getListViewId() {
        return 0;
    }

    @Override
    protected void initView(Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        titleBar.getLlLeft().setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                SettingActivity.this.finish();
            }
        });
        mivVersion.setLeftText(String.format(getResources().getString(R.string.setting_version), AppUtils.getAppVersionName(this)));
        boolean sound = SpUtils.getBoolean(this, "sound", true);
        if (sound) {
            ivSound.setImageResource(R.mipmap.ic_sound_on);
        } else {
            ivSound.setImageResource(R.mipmap.ic_sound_off);
        }
    }

    @OnClick({R.id.miv_account, R.id.miv_version, R.id.btn_login_out, R.id.rl_sound})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.miv_account:
                startActivity(AccountActivity.class);
                break;
            case R.id.rl_sound:
                boolean sound = SpUtils.getBoolean(this, "sound", true);
                if (sound) {
                    ivSound.setImageResource(R.mipmap.ic_sound_off);
                    SpUtils.putBoolean(this, "sound", false);
                } else {
                    ivSound.setImageResource(R.mipmap.ic_sound_on);
                    SpUtils.putBoolean(this, "sound", true);
                }
                break;
            case R.id.miv_version:
                break;
            case R.id.btn_login_out:
                APP.Token = "";
                APP.uid = "";
                APP.userInfo = null;
                Intent intent = new Intent();
                intent.putExtra("is_auto", false);
                AppManager.getAppManager().finishAllActivity();
                startActivity(LoginActivity.class, intent);
                this.finish();
                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }
}
